﻿using System.Collections.Generic;

namespace ConsoleAppFramework.Rmq
{
    public class RmqConnectPoolFactory
    {
        private static Dictionary<string, RmqConnectPool> _poolDic = new Dictionary<string, RmqConnectPool>();

        private static object lock_obj = new object();

        public static RmqConnectPool GetClientPool(string connect, int poolSize = 5, int checkSleepSecs = 3)
        {
            if (!_poolDic.ContainsKey(connect))
            {
                lock (lock_obj)
                {
                    if (!_poolDic.ContainsKey(connect))
                    {
                        _poolDic[connect] = new RmqConnectPool(connect, poolSize, checkSleepSecs);
                        _poolDic[connect].GetConnect();
                    }
                }
            }

            return _poolDic[connect];
        }

        public static RmqConnectPool GetClientPool(RmqUrlEnum urlEnum, int poolSize = 5, int checkSleepSecs = 3)
        {
            string connect = string.Empty;

            switch (urlEnum)
            {
                case RmqUrlEnum.Douyin:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.XiGuaWx:
                    connect = "amqp://admin:admin@43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.WeiBo:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.XiaoHongShu:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.KuaiShou:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.ZhiGua:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.BStation:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.JiGua:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                case RmqUrlEnum.ZhiGua_New:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
                default:
                    connect = "amqp://43.142.4.243:5672/Xigua.Shusi";
                    break;
            }

            return GetClientPool(connect, poolSize, checkSleepSecs);
        }
    }
}
